package it.blueocean.acanto.taglibrary.jsp.taglib.tags.navigation;

import it.blueocean.acanto.entities.platform.MenuItem;
import it.blueocean.acanto.taglibrary.jsp.taglib.navigation.NavigationTag;

import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import javax.servlet.jsp.JspWriter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class TabbedMenuTag extends NavigationTag
{
	private static final long serialVersionUID = -3204927301435089709L;

	private final static Logger logger = LoggerFactory.getLogger(TabbedMenuTag.class);

	protected void createHTML(MenuItem paramMenuItem, JspWriter paramJspWriter) throws IOException
	{
		int i = 0;
		List<MenuItem> localList = paramMenuItem.getChildren();
		int j = localList.size();
		paramJspWriter.write("<ul>");
		Iterator<MenuItem> localIterator = localList.iterator();
		while (localIterator.hasNext())
		{
			MenuItem localMenuItem = localIterator.next();
			if((i == 0) && (i == j - 1))
			{
				paramJspWriter.write("<li class=\"first-selected\"> </li>");
				paramJspWriter.write("<li class=\"tab-selected\">");
				paramJspWriter.write(getHref(localMenuItem.getId(), localMenuItem.getTitle()));
				paramJspWriter.write("</li>");
				paramJspWriter.write("<li class=\"last-selected\"> </li>");
			}
			else if((i == 0) && (i < j - 1))
			{
				if(localMenuItem.isSelected())
				{
					paramJspWriter.write("<li class=\"first-selected\"> </li>");
					paramJspWriter.write("<li class=\"tab-selected\">");
					paramJspWriter.write(getHref(localMenuItem.getId(), localMenuItem.getTitle()));
					paramJspWriter.write("</li>");
					paramJspWriter.write("<li class=\"dx-selected\"> </li>");
				}
				else if((localList.get(i + 1) != null) && (((MenuItem) localList.get(i + 1)).isSelected()))
				{
					paramJspWriter.write("<li class=\"first-not-selected\"> </li>");
					paramJspWriter.write("<li class=\"tab-not-selected\">");
					paramJspWriter.write(getHref(localMenuItem.getId(), localMenuItem.getTitle()));
					paramJspWriter.write("</li>");
					paramJspWriter.write("<li class=\"sx-selected\"> </li>");
				}
				else
				{
					paramJspWriter.write("<li class=\"first-not-selected\"> </li>");
					paramJspWriter.write("<li class=\"tab-not-selected\">");
					paramJspWriter.write(getHref(localMenuItem.getId(), localMenuItem.getTitle()));
					paramJspWriter.write("</li>");
					paramJspWriter.write("<li class=\"mid-not-selected\"> </li>");
				}
			}
			else if((i > 0) && (i < j - 1))
			{
				if(localMenuItem.isSelected())
				{
					paramJspWriter.write("<li class=\"tab-selected\">");
					paramJspWriter.write(getHref(localMenuItem.getId(), localMenuItem.getTitle()));
					paramJspWriter.write("</li>");
					paramJspWriter.write("<li class=\"dx-selected\"> </li>");
				}
				else if((localList.get(i + 1) != null) && (((MenuItem) localList.get(i + 1)).isSelected()))
				{
					paramJspWriter.write("<li class=\"tab-not-selected\">");
					paramJspWriter.write(getHref(localMenuItem.getId(), localMenuItem.getTitle()));
					paramJspWriter.write("</li>");
					paramJspWriter.write("<li class=\"sx-selected\"> </li>");
				}
				else
				{
					paramJspWriter.write("<li class=\"tab-not-selected\">");
					paramJspWriter.write(getHref(localMenuItem.getId(), localMenuItem.getTitle()));
					paramJspWriter.write("</li>");
					paramJspWriter.write("<li class=\"mid-not-selected\"> </li>");
				}
			}
			else if(localMenuItem.isSelected())
			{
				paramJspWriter.write("<li class=\"tab-selected\">");
				paramJspWriter.write(getHref(localMenuItem.getId(), localMenuItem.getTitle()));
				paramJspWriter.write("</li>");
				paramJspWriter.write("<li class=\"last-selected\"> </li>");
			}
			else
			{
				paramJspWriter.write("<li class=\"tab-not-selected\">");
				paramJspWriter.write(getHref(localMenuItem.getId(), localMenuItem.getTitle()));
				paramJspWriter.write("</li>");
				paramJspWriter.write("<li class=\"last-not-selected\"> </li>");
			}
			++i;
		}
		paramJspWriter.write("</ul>");
	}
}
